﻿<?php require_once('../wp-blog-header.php'); ?>
<?php get_header(); ?>
<SCRIPT type=text/javascript src="javascripts.js"></SCRIPT>
<?php
	// require_once('checkSession.php');
	require_once('conn.php');
	
	$month=$_GET['m'];
	$year=$_GET['y'];
	$shopID=$_GET['s'];

	$month_1=($month-1+12)%12;
	$month_2=($month-2+12)%12;
	$month_3=($month-3+12)%12;
	
	if ($month_1 == 0) $month_1=12;
	if ($month_2 == 0) $month_2=12;
	if ($month_3 == 0) $month_3=12;
	
	$year_1 = $year;
	$year_2 = $year;
	$year_3 = $year;
	
	if ($month_1 > $month)
	{
		$year_1 = $year-1;
	}
	if ($month_2 > $month)
	{
		$year_2 = $year-1;
	}
		if ($month_3 > $month)
	{
		$year_3 = $year-1;
	}
	
	echo '<table border="8">';
	echo '<tr>';
		echo '<th>'; echo '<input type="text" value="日期" disable="disable">'; echo '</th>';	
		echo '<th>'; echo '<input type="text" value="单数" disable="disable">'; echo '</th>';		
		echo '<th>'; echo '<input type="text" value="销售额" disable="disable">'; echo '</th>';
		echo '<th>'; echo '<input type="text" value="备注" disable="disable">'; echo '</th>';
	echo '</tr>';	
	for ($day=1; $day<=31; $day++)
	{  
		// 每月31条记录，逐条输出
		$ymd = $year.'-'.$month.'-'.$day;
		$exec = "select count(*) from buyRecord where day(buyDate)='".$day."' and month(buyDate)='".$month."' and year(buyDate)='".$year."' and shopID='".$shopID."'";
		$result = mysql_query($exec);		
		$row=mysql_fetch_row($result);
		//var_dump($row);
		$dayCount=$row[0];
		$exec = "select sum(score) from buyRecord where day(buyDate)='".$day."' and month(buyDate)='".$month."' and year(buyDate)='".$year."' and shopID='".$shopID."'";
		$result = mysql_query($exec);		
		$row=mysql_fetch_row($result);		
		$daySum=$row[0];
		echo '<tr>';
			echo '<td>'; echo '<input type="text" value='.$ymd.' disable="disable">'; echo '</td>';	
			echo '<td>'; echo '<input type="text" disable="disable" value='.$dayCount.'>'; echo '</td>';		
			echo '<td>'; echo '<input type="text" disable="disable" value='.$daySum.'>'; echo '</td>';		
		echo '</tr>';
	}
	echo '</table>';
	
	echo '<hr>';
	
	
	echo '<table border="8">';
		echo '<tr>';
			echo '<td>'; echo '<input type="text" value="" disable="disable">'; echo '</td>';
			$ym = $year.'-'.$month;
			echo '<td>'; echo '<input type="text" value='.$ym.' disable="disable">'; echo '</td>';
			$ym = $year_1.'-'.$month_1;
			echo '<td>'; echo '<input type="text" value='.$ym.' disable="disable">'; echo '</td>';
			$ym = $year_2.'-'.$month_2;
			echo '<td>'; echo '<input type="text" value='.$ym.' disable="disable">'; echo '</td>';
			$ym = $year_3.'-'.$month_3;
			echo '<td>'; echo '<input type="text" value='.$ym.' disable="disable">'; echo '</td>';			
		echo '</tr>';
		
		echo '<tr>';
			echo '<td>'; echo '<input type="text" value="月总销售额" disable="disable">'; echo '</td>';
			
			$exec = "select sum(score) from buyRecord where month(buyDate)='".$month."' and year(buyDate)='".$year."' and shopID='".$shopID."'";
			$result = mysql_query($exec);		
			$row=mysql_fetch_row($result);
			$value=$row[0];
			echo '<td>'; echo '<input type="text" value='.$value.' disable="disable">'; echo '</td>';			
			
			$exec = "select sum(score) from buyRecord where month(buyDate)='".$month_1."' and year(buyDate)='".$year_1."' and shopID='".$shopID."'";
			$result = mysql_query($exec);		
			$row=mysql_fetch_row($result);
			$value=$row[0];
			echo '<td>'; echo '<input type="text" value='.$value.' disable="disable">'; echo '</td>';	

			$exec = "select sum(score) from buyRecord where month(buyDate)='".$month_2."' and year(buyDate)='".$year_2."' and shopID='".$shopID."'";
			$result = mysql_query($exec);		
			$row=mysql_fetch_row($result);
			$value=$row[0];
			echo '<td>'; echo '<input type="text" value='.$value.' disable="disable">'; echo '</td>';	

			$exec = "select sum(score) from buyRecord where month(buyDate)='".$month_3."' and year(buyDate)='".$year_3."' and shopID='".$shopID."'";
			$result = mysql_query($exec);		
			$row=mysql_fetch_row($result);
			$value=$row[0];
			echo '<td>'; echo '<input type="text" value='.$value.' disable="disable">'; echo '</td>';				
			
		echo '</tr>';		
		
		echo '<tr>';
			echo '<td>'; echo '<input type="text" value="月总单数" disable="disable">'; echo '</td>';
			
			$exec = "select count(*) from buyRecord where month(buyDate)='".$month."' and year(buyDate)='".$year."' and shopID='".$shopID."'";
			$result = mysql_query($exec);		
			$row=mysql_fetch_row($result);
			$value=$row[0];
			echo '<td>'; echo '<input type="text" value='.$value.' disable="disable">'; echo '</td>';			
			
			$exec = "select count(*) from buyRecord where month(buyDate)='".$month_1."' and year(buyDate)='".$year_1."' and shopID='".$shopID."'";
			$result = mysql_query($exec);		
			$row=mysql_fetch_row($result);
			$value=$row[0];
			echo '<td>'; echo '<input type="text" value='.$value.' disable="disable">'; echo '</td>';	

			$exec = "select count(*) from buyRecord where month(buyDate)='".$month_2."' and year(buyDate)='".$year_2."' and shopID='".$shopID."'";
			$result = mysql_query($exec);		
			$row=mysql_fetch_row($result);
			$value=$row[0];
			echo '<td>'; echo '<input type="text" value='.$value.' disable="disable">'; echo '</td>';	

			$exec = "select count(*) from buyRecord where month(buyDate)='".$month_3."' and year(buyDate)='".$year_3."' and shopID='".$shopID."'";
			$result = mysql_query($exec);		
			$row=mysql_fetch_row($result);
			$value=$row[0];
			echo '<td>'; echo '<input type="text" value='.$value.' disable="disable">'; echo '</td>';				
			
		echo '</tr>';		

		echo '<tr>';
			echo '<td>'; echo '<input type="text" value="月单笔均价" disable="disable">'; echo '</td>';
			
			$exec = "select avg(score) from buyRecord where month(buyDate)='".$month."' and year(buyDate)='".$year."' and shopID='".$shopID."'";
			$result = mysql_query($exec);		
			$row=mysql_fetch_row($result);
			$value=$row[0];
			echo '<td>'; echo '<input type="text" value='.$value.' disable="disable">'; echo '</td>';			
			
			$exec = "select avg(score) from buyRecord where month(buyDate)='".$month_1."' and year(buyDate)='".$year_1."' and shopID='".$shopID."'";
			$result = mysql_query($exec);		
			$row=mysql_fetch_row($result);
			$value=$row[0];
			echo '<td>'; echo '<input type="text" value='.$value.' disable="disable">'; echo '</td>';	

			$exec = "select avg(score) from buyRecord where month(buyDate)='".$month_2."' and year(buyDate)='".$year_2."' and shopID='".$shopID."'";
			$result = mysql_query($exec);		
			$row=mysql_fetch_row($result);
			$value=$row[0];
			echo '<td>'; echo '<input type="text" value='.$value.' disable="disable">'; echo '</td>';	

			$exec = "select avg(score) from buyRecord where month(buyDate)='".$month_3."' and year(buyDate)='".$year_3."' and shopID='".$shopID."'";
			$result = mysql_query($exec);		
			$row=mysql_fetch_row($result);
			$value=$row[0];
			echo '<td>'; echo '<input type="text" value='.$value.' disable="disable">'; echo '</td>';				
			
		echo '</tr>';			
	echo '</table>';
	
?>
<?php get_footer(); ?>